{include file="common/_header"}
{include file="common/_header1"}

<body class="layui-anim layui-anim-up">
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">报表管理</a>
            <a>
              <cite>商铺订单管理</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="x-body">

    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so " id="form1">
            <div class="layui-input-inline">

                <div class="layui-unselect layui-form-select paystate" style="display:inline-block;">
                    <select name="order_status" lay-filter="pay_status">
                        <option value="">订单状态</option>
                        {volist name="data.statelist" id="vo"}
                        <option value={$key} {$data.get.order_status == $key?'selected':''}>{$vo}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="time" class="layui-input" id="test1" placeholder="请选择时间" readonly value="{$data.get.time}">
                </div>
                <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
<!--                <button class="layui-btn"  lay-submit="" lay-filter="sreach" onclick="importData()">导出</button>-->
            </div>

        </form>
    </div>

    <table id="tables" class="layui-table">
        <thead>
        <tr>
            <th>订单号</th>
            <th>下单姓名</th>
            <th>联系电话</th>
            <th>配送地址</th>
            <th>订单状态</th>
            <th>购买数量</th>
            <th>订单金额</th>
            <th>购买商品</th>
            <th>日期</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="data.data.data" id="vo"}
        <tr class="table_tr">
            <td>{$vo.orderno}</td>
            <td>{$vo.receive_name}</td>
            <td>{$vo.r_phone}</td>
            <td>{$vo.r_address}</td>
            <td>{$data['statelist'][$vo.order_status]}</td>
            <td>{$vo.total}</td>
            <td>
                订单总价：{$vo.order_amount}<br>
                支付金额：{$vo.pay_amount}
            </td>
            <td>
                {volist name="vo.order_details" id="v"}
                    {$v.product_name}——{$v.p_s_name}(数量:{$v.quantity}  售价:{$v.sale_price})<br><br>
                {/volist}
            </td>
            <td>
                下单时间：{$vo.order_time|date="Y-m-d H:i:s"}<br>
                {if !empty($vo.pay_time)}支付时间：{$vo.pay_time|date="Y-m-d H:i:s"}{/if}
                {if !empty($vo.receive_time)}期望配送时间：{$vo.receive_time|date="Y-m-d H:i:s"}{/if}
            </td>
            <td>
                <ul class="nav navbar-nav" style=" height: 30px; line-height: 10px;">
                    <li class="dropdown" style="height: 100%;">
                        {if $vo.order_status == 2 || $vo.order_status == 6}
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" style=" height: 100%; line-height: 5px;">
                            操作
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu">
                            {if $vo.order_status == 2}
                            <li><a title="确认发货" onclick="OperateMakeMeal('sureshipments?order_id={$vo.order_id}')" href="javascript:;">确认发货</a></li>
                            <li class="divider"></li>
                            <li><a title="商家退款" onclick="OperateMakeMeal('shoprefund?order_id={$vo.order_id}')" href="javascript:;">商家退款</a></li>
                            {/if}
                            {if $vo.order_status == 6}
                            <li><a title="取消用户撤销" onclick="OperateMakeMeal('canceluser?order_id={$vo.order_id}')" href="javascript:;">取消用户撤销</a></li>
                            <li class="divider"></li>
                            <li><a title="确认退款" onclick="OperateMakeMeal('sureUserRefund?order_id={$vo.order_id}')" href="javascript:;">确认退款</a></li>
                            {/if}
                        </ul>
                        {/if}
                    </li>
                </ul>
            </td>

        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page_all">
        {$page|raw}
    </div>
</div>
<script src="/static/admin/lib/layui/layui2.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use('laydate', function(){
        let laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#test1'
            , range: true
        });

        //国际版
        laydate.render({
            elem: '#test1-1'
            ,lang: 'en'
        });
    });
</script>
<script>
    layui.use("form",function(){
        var form = layui.form;
        form.on('select(spf_id)', function (sub) {
            console.log(sub.value);
            selectedProducts(sub.value,'');
        });
    })
</script>
<script>

    $(function () {
        // 表格选中行的同时选中单选框
        $("#tables tr:gt(0)").click(function () {
            $(this).find(":radio").prop("checked", true);
        });

    });

    //js放到table下，才能检测到tr数组
    var trs = document.getElementById("tables").getElementsByTagName("tr");
    $(function () {
        for (var i = 0; i < trs.length; i++) {
            trs[i].onmousedown = function () {
                mousedownclick(this);
            }
        }
    });

    function mousedownclick(obj) {
        for (var j = 0; j < trs.length; j++) {
            if (trs[j] == obj) {
                if (trs[0] != obj) {
                    trs[j].style.background = '#D0E9C6';
                    // 启用新增和编辑按钮
                    $("#edits").removeAttr("disabled");//启用按钮
                    $('#edits').removeClass('layui-disabled');
                }
            } else {
                trs[j].style.background = '';
            }
        }
    }
    function OperateMakeMeal(url) {
        layer.confirm('您确定要进行操作?', {btn: ['确定', '取消'], title: "提示"}, function () {
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    if(data.code == 1){
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 500,
                        }, function () {
                            window.location.reload();
                        })
                    } else {
                        layer.msg(data.msg, {
                            icon: 5,
                            time: 500,
                        })
                    }
                }
            })
        });
    }
    function importData() {
        // console.log( $("#form1").serialize())
        // $.ajax({
        //     type: 'post',
        //     url: '/orders/importoffline',
        //     data: $("#form1").serialize(),
        //     dataType:"json",
        //     async:true,
        //     success: function(data) {
        //
        //     }})
        x=$("#form1").serializeArray();
        let string = ''
        $.each(x, function(i, field){
            if(string != ''){
                string += '&'+field.name+'='+field.value
            } else {
                string = field.name+'='+field.value
            }
        });
        url = '/orders/importoffline?'+string;
        console.log(url);
        // window.location.href = url;
        window.open('_blank').location.href = url;
        // window.open(url,'_self');
        // window.location.replace(url)
    }
</script>
</body>

{include file="common/_bottom"}